package com.itjiange;

/**
 * 组合模式
 *
 * @author ItJianGe
 * @data 2024/8/13 11:10
 */
public class CompositeDemoMain {
    public static void main(String[] args) {

        LeadingStaff leadingStaff1 = new LeadingStaff("A", "董事长");
        LeadingStaff leadingStaff2 = new LeadingStaff("B", "项目经理");
        LeadingStaff leadingStaff3 = new LeadingStaff("C", "职能经理");
        BottomStaff bottomStaff1 = new BottomStaff("B1", "程序员1");
        BottomStaff bottomStaff2 = new BottomStaff("B2", "程序员2");
        BottomStaff bottomStaff3 = new BottomStaff("C1", "其他人员");

        leadingStaff1.addAllStaff(leadingStaff2, leadingStaff3);
        leadingStaff2.addAllStaff(bottomStaff1, bottomStaff2);
        leadingStaff3.addAllStaff(bottomStaff3);

        System.out.println("------董事长的下属------");
        printAllStaffInfo(leadingStaff1);
        System.out.println("------项目经理的下属------");
        printAllStaffInfo(leadingStaff2);
        System.out.println("------职能经理的下属------");
        printAllStaffInfo(leadingStaff3);
    }

    private static void printAllStaffInfo(LeadingStaff leadingStaff) {
        for (Staff staff : leadingStaff.getAllStaffInfo()) {
            System.out.printf("姓名：%s ------ 职位：%s\n", staff.getName(), staff.getPosition());
            if (staff instanceof LeadingStaff) {
                printAllStaffInfo((LeadingStaff) staff);
            }
        }
    }
}